﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Xml.Linq;

namespace NetLogger
{
	public class NetPost
	{
		public NetPost( string page )
		{
			_page = page;
		}

		private Dictionary<string, string> _data = new Dictionary<string, string>();
		public Dictionary<string, string> Data
		{
			get
			{
				return _data;
			}
		}

		private string _page;
		public string Page
		{
			get
			{
				return _page;
			}
		}

		public static DateTimeOffset FromMySQLDate( XElement node )
		{
			return DateTimeOffset.ParseExact( DecodedString( node ), Properties.Resources.MySQLDateTimeFormat, null,
				System.Globalization.DateTimeStyles.AssumeUniversal );
		}

		public static string ToMySQLDate( DateTimeOffset date )
		{
			return date.ToString( Properties.Resources.MySQLDateTimeFormat );
		}

		public static string FromBoolean( bool value )
		{
			return value ? "1" : "0";
		}

		public static bool ToBoolean( XElement node )
		{
			return ( string ) node == "1";
		}

		public static string DecodedString( XElement node )
		{
			return WebUtility.HtmlDecode( ( string ) node );
		}
	}
}
